package com.example.usage.aop.auth;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author jiangzhe
 * @create 2022/9/1 17:58
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    // http://localhost:8082/admin/auth/admin?userID=01
    @NeedWhite(auth = "admin",methodName = "failAuthAdmin")
    @GetMapping("/auth/admin")
    public Result authAdmin() {
        Result result = new Result();
        result.setCode(200).setMsg("访问成功")
                .setData(UUID.randomUUID()
                        .toString().replace("-", ""));
        return result;
    }

    // http://localhost:8082/admin/auth/user?userID=02
    @NeedWhite(auth = "user",methodName = "failAuthAdmin")
    @GetMapping("/auth/user")
    public Result authUser() {
        Result result = new Result();
        result.setCode(200).setMsg("访问成功")
                .setData(UUID.randomUUID()
                        .toString().replace("-", ""));
        return result;
    }

    public Result failAuthAdmin()
    {
        Result result = new Result();
        result.setCode(403).setMsg("访问失败,权限不足");
        return result;
    }
}